from app import db
from datetime import datetime

class PlantingData(db.Model):
    __tablename__ = 'planting_data'
    
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    crop_type = db.Column(db.String(50), nullable=False)
    area = db.Column(db.Float, nullable=False)  # 种植面积（亩）
    region = db.Column(db.String(100), nullable=False)  # 种植区域
    plot_number = db.Column(db.String(50))  # 地块编号
    planting_date = db.Column(db.Date, nullable=False)  # 种植日期
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    
    user = db.relationship('User', backref='planting_data')

class CropVariety(db.Model):
    __tablename__ = 'crop_varieties'
    
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    crop_type = db.Column(db.String(50), nullable=False)
    characteristics = db.Column(db.Text)  # 品种特性
    yield_potential = db.Column(db.String(100))  # 产量潜力
    market_value = db.Column(db.String(100))  # 市场价值
    created_at = db.Column(db.DateTime, default=datetime.utcnow)

class EnvironmentData(db.Model):
    __tablename__ = 'environment_data'
    
    id = db.Column(db.Integer, primary_key=True)
    region = db.Column(db.String(100), nullable=False)
    date = db.Column(db.Date, nullable=False)
    temperature = db.Column(db.Float)  # 温度
    rainfall = db.Column(db.Float)  # 降雨量
    soil_type = db.Column(db.String(50))  # 土壤类型
    soil_fertility = db.Column(db.String(50))  # 土壤肥力
    light_intensity = db.Column(db.Float)  # 光照强度
    created_at = db.Column(db.DateTime, default=datetime.utcnow) 